<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>人事管理系统 ——用户管理</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link href="../css/css.css" type="text/css" rel="stylesheet" />
	<link rel="stylesheet" type="text/css" href="../js/ligerUI/skins/Aqua/css/ligerui-dialog.css"/>
	<link href="../js/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="../js/jquery-1.11.0.js"></script>
    <script type="text/javascript" src="../js/jquery-migrate-1.2.1.js"></script>
	<script src="../js/ligerUI/js/core/base.js" type="text/javascript"></script>
	<script src="../js/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script> 
	<script src="../js/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
	<script src="../js/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
	<link href="../css/pager.css" type="text/css" rel="stylesheet" />
	<script type="text/javascript">
		//查询用户列表的函数
		function search() {
			var username = $("[name=username]").val();//获取登录名
			var role = $("[name=status]").val();//获取角色
			$.get(
					"/user/list",
					{
						"loginname":username,
						"role":role
					},
					function (data) {
						$("#tb-users tbody").empty();
						for (var i in data){
							var tr = $("<tr></tr>");
							//新建一个不带行信息的空白复选框
							var input_chk = $('<input type="checkbox" id="" value="">');
							input_chk.attr("id","box_" + data[i].id);
							input_chk.val(data[i].id);
							tr.append('<td align="center"></td>');
							tr.children("td").eq(0).append(input_chk);
							tr.append("<td>" + data[i].loginname + "</td>");
							tr.append("<td>"+ data[i].password + "</td>");
							tr.append("<td>"+ data[i].username + "</td>");
							if(data[i].role==1){
								tr.append("<td>" + "管理员" + "</td>");
							}
							if(data[i].role==2){
								tr.append("<td>" + "普通用户" + "</td>");
							}
							tr.append("<td>" + data[i].createdate + "</td>");
							tr.append('<td align="center"><a href=""><img title="修改" src="../images/update.gif"></a></td>');
							tr.find("a").attr("href","/user/showUpdateUser?id=" + data[i].id);
							$("#tb-users tbody").append(tr);
						}
					}
			);
		}
		$(function(){

	 	   
	 	  /** 给数据行绑定鼠标覆盖以及鼠标移开事件  */
	    	$("tr[id^='data_']").hover(function(){
	    		$(this).css("backgroundColor","#eeccff");
	    	},function(){
	    		$(this).css("backgroundColor","#ffffff");
	    	})
	    
	    	
	 	   /** 删除员工绑定点击事件 */
	 	   $("#delete").click(function(){
			   /** 获取上一次选中的部门数据 */
			   var boxs  = $("input[type='checkbox'][id^='box_']");
			   /** 获取到用户选中的复选框  */
			   var checkedBoxs = boxs.filter(":checked");
	 		   if(checkedBoxs.length < 1){
	 			   $.ligerDialog.error("请选择一个需要删除的用户！");
	 		   }else{
	 			   /** 得到用户选中的所有的需要删除的ids */
	 			   var ids = checkedBoxs.map(function(){
	 				   return this.value;
	 			   })
	 			   
	 			   $.ligerDialog.confirm("确认要删除吗?","删除用户",function(r){
	 				   if(r){
	 				   	console.log(ids.get());
	 				   	$.ajax({
							url:"/user/delete",
							type:"post",
							contentType:"application/json",
							data:JSON.stringify(ids.get()),
							success:function () {
								$.ligerDialog.alert("用户删除成功");
								checkedBoxs.parent("td").parent("tr").remove();
							}
						});
	 					   // alert("删除："+ids.get());
	 					   // 发送请求
	 					  // window.location = "${ctx }/user/removeUser?ids=" + ids.get();
	 				   }
	 			   });
	 		   }
	 	   })
	    })

	</script>
</head>
<body>
	<!-- 导航 -->
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	  <tr><td height="10"></td></tr>
	  <tr>
	    <td width="15" height="32"><img src="../images/main_locleft.gif" width="15" height="32"></td>
		<td class="main_locbg font2"><img src="../images/pointer.gif">&nbsp;&nbsp;&nbsp;当前位置：用户管理 &gt; 用户查询</td>
		<td width="15" height="32"><img src="../images/main_locright.gif" width="15" height="32"></td>
	  </tr>
	</table>
	
	<table width="100%" height="90%" border="0" cellpadding="5" cellspacing="0" class="main_tabbor">
	  <!-- 查询区  -->
	  <tr valign="top">
	    <td height="30">
		  <table width="100%" border="0" cellpadding="0" cellspacing="10" class="main_tab">
		    <tr>
			  <td class="fftd">
			  	
				    <table width="100%" border="0" cellpadding="0" cellspacing="0">
					  <tr>
					    <td class="font3">
					    	用户名：<input type="text" name="username">
					    	用户角色：<select name="status">
					    			<option value="0">全部</option>
									<option value="1">管理员</option>
									<option value="2">普通用户</option>
									</select>
					    	 <input type="button" value="搜索" onclick="search()"/>
					    	<input id="delete" type="button" value="删除"/>
							<script type="text/javascript">
								var role = "${loginUser.role eq 1?'admin':'user'}";
								if(role=='user'){
									$("#delete").hide();//普通用户不应有删除权限，隐藏删除按钮
								}
							</script>
					    </td>
					  </tr>
					</table>
			
			  </td>
			</tr>
		  </table>
		</td>
	  </tr>
	  
	  <!-- 数据展示区 -->
	  <tr valign="top">
	    <td height="20">
		  <table id="tb-users" width="100%" border="1" cellpadding="5" cellspacing="0" style="border:#c2c6cc 1px solid; border-collapse:collapse;">
		    <thead><tr class="main_trbg_tit" align="center">
			  <td><input type="checkbox" name="checkAll" id="checkAll"></td>
			  <td>登录名</td>
			  <td>密码</td>
			  <td>用户名</td>
			  <td>状态</td>
			  <td>创建时间</td>
			  	
			  <td align="center">操作</td>
			   
			</tr>
		  </thead>
		  <tbody></tbody>
		  </table>
		</td>
	  </tr>
	  <!-- 分页标签 -->
	  <tr valign="top"><td align="center" class="font3">
	  	 <table width="100%" align="center" style="font-size:13px;" class="digg"><tbody><tr><td style="COLOR: #0061de; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; TEXT-DECORATION: none"><span class="disabled">上一页</span><span class="current">1</span><span class="disabled">下一页</span>&nbsp;跳转到&nbsp;&nbsp;<input style="text-align: center;BORDER-RIGHT: #aaaadd 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #aaaadd 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #aaaadd 1px solid; COLOR: #000099; PADDING-TOP: 2px; BORDER-BOTTOM: #aaaadd 1px solid; TEXT-DECORATION: none" type="text" size="2" id="pager_jump_page_size">&nbsp;<input type="button" style="text-align: center;BORDER-RIGHT: #dedfde 1px solid; PADDING-RIGHT: 6px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #dedfde 1px solid; PADDING-LEFT: 6px; PADDING-BOTTOM: 2px; BORDER-LEFT: #dedfde 1px solid; COLOR: #0061de; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #dedfde 1px solid; TEXT-DECORATION: none" value="确定" id="pager_jump_btn"></td></tr><tr align="center"><td style="font-size:13px;"></td></tr><tr><td style="COLOR: #0061de; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; TEXT-DECORATION: none">总共<font color="red">2</font>条记录，当前显示1-2条记录。</td></tr></tbody></table>
	  </td></tr>
	</table>
	<div style="height:10px;"></div>
</body>
</html>